package com.fizzkai.p2p.bussness.service.impl;

import com.fizzkai.p2p.bussness.domain.SystemAccount;
import com.fizzkai.p2p.bussness.mapper.SystemAccountMapper;
import com.fizzkai.p2p.bussness.service.ISystemAccountService;
import com.fizzkai.p2p.core.util.AssertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service@Transactional
public class SystemAccountServiceImpl implements ISystemAccountService {
    @Autowired
    private SystemAccountMapper accountMapper;

    @Override
    public int save(SystemAccount entity) {
        return accountMapper.insert(entity);
    }

    @Override
    public int update(SystemAccount entity) {
        int row = accountMapper.updateByPrimaryKey(entity);
        AssertUtil.updateNotZero(row);
        return row;
    }

    @Override
    public SystemAccount getCurrent() {
        return accountMapper.selectCurrent();
    }

    @Override
    public void initSystemAccount() {
        SystemAccount current = this.getCurrent();
        if (current == null) {
            this.save(new SystemAccount());
        }
    }

}
